package blog.controller.articles;

import blog.service.ArticleService;
import blog.vo.ArticleVo;
import blog.vo.params.ArticleParam;
import blog.vo.params.PageParams;
import blog.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/articles")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    // 显示所有文章
    @PostMapping
    public Result listArticle(@RequestBody PageParams pageParams) {

        return articleService.listArticles(pageParams);

    }

    // 最热文章
    @PostMapping("/hot")
    public Result hotArticle() {
        Integer limit = 3; // 取前几条热门文章

        return articleService.hotArticles(limit);
    }

    // 最新文章
    @PostMapping("/new")
    public Result lastArticle() {
        Integer limit = 3; // 取前几条热门文章

        return articleService.lastArticles(limit);
    }

    // 文章归档
    @PostMapping("/listArchives")
    public Result listArchives() {

        return articleService.listArchives();
    }


    // 根据文章id查找文章具体内容
    @PostMapping("/view/{id}")
    public Result findArticleById(@PathVariable("id") Long id) {

        return articleService.findArticleById(id);
    }


    // 发布文章
    @PostMapping("/publish")
    public Result publish(@RequestBody ArticleParam articleParam) {

        return articleService.publish(articleParam);
    }
}
